<template>
  <div>
    <h2>代码压缩</h2>
    <pre class="code">{{compressed}}</pre>
    <pre class="code">{{treeCompressed}}</pre>
  </div>
</template>

<script type="text/javascript">
import compressCode from '@/list-walker/compress';
import Walker from '@/walker';
import CompressWalker from '@/walker/compress';
import code from '@/code/program';
import getTokenList from '@/utils/getTokenList';

const acorn = require('acorn');

export default {
  data() {
    const tokenList = getTokenList(code);
    const tree = acorn.parse(code);

    const compressed = compressCode(tokenList);

    const treeCompressed = new Walker(CompressWalker, {}).walk(tree);

    return {
      compressed,
      treeCompressed,
    }
  },
};
</script>

<style type="text/css">
</style>
